package swu.edu.cn.javaee.service;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import swu.edu.cn.javaee.entity.Merchant;
import swu.edu.cn.javaee.entity.Product;
import swu.edu.cn.javaee.entity.SearchInfo;
import swu.edu.cn.javaee.mapper.MerchantMapper;
import swu.edu.cn.javaee.mapper.ProductMapper;

import java.io.Serial;
import java.util.List;

@Service
public class SearchService {

    @Resource
    private MerchantMapper merchantMapper;
    @Resource
    private ProductMapper productMapper;


    /**
     * 模糊查询，返回商户信息和产品信息
     * */
    public SearchInfo searchByInput(String In){
        SearchInfo searchInfo=new SearchInfo();
        List<Merchant> list1=merchantMapper.queryByInput(In);
        List<Product> list2=productMapper.queryByInput(In);
        if(list1.size()!=0 || list2.size()!=0){
            System.out.println(list1);
            System.out.println(list2);
            searchInfo.setCode("0");
            searchInfo.setMerchants(list1);
            searchInfo.setProducts(list2);
        }else {
            searchInfo.setCode("1");
            System.out.println(searchInfo);
        }
        return searchInfo;
    }
}
